package com.jzy.gulimall.cart.vo;

import cn.hutool.core.collection.CollectionUtil;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author jzy
 * @date 2020/9/18 14:05
 * 购物车
 */
public class CartVo {

    private List<CartItemVo> cartItemVos;

    private Integer countNum; //商品数量

    private Integer countType; //商品类型

    private BigDecimal totalAmount; //商品总价

    private BigDecimal reduce = new BigDecimal(0);  //减免价格

    public List<CartItemVo> getCartItemVos() {
        return cartItemVos;
    }

    public void setCartItemVos(List<CartItemVo> cartItemVos) {
        this.cartItemVos = cartItemVos;
    }

    /**
     * 获取商品总数量
     */
    public Integer getCountNum() {
        int count = 0;
        if (CollectionUtil.isNotEmpty(cartItemVos)) {
            for (CartItemVo itemVo : cartItemVos) {
                count += itemVo.getCount();
            }
        }
        return count;
    }

    /**
     * 获取商品类型数量
     */
    public Integer getCountType() {
        int count = 0;
        if (CollectionUtil.isNotEmpty(cartItemVos)) {
            for (CartItemVo itemVo : cartItemVos) {
                count += 1;
            }
        }
        return count;
    }

    /**
     * 获取商品总价格
     */
    public BigDecimal getTotalAmount() {
        BigDecimal decimal = new BigDecimal(0);
        //购物项总价
        if (CollectionUtil.isNotEmpty(cartItemVos)) {
            for (CartItemVo itemVo : cartItemVos) {
                if (itemVo.getCheck()) {
                    decimal = decimal.add(itemVo.getTotalPrice());
                }
            }
        }
        //减去优惠价格
        return decimal.subtract(reduce);
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
